package com.zzh.test1;

/**
 * 测试中断学习
 */
public class Test1 {
    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            while (true){
                System.out.println("t1 is running");
                if (Thread.currentThread().isInterrupted()){
                    System.out.println("线程被中断");
                    break;
                }
            }
        }, "t1");
        t1.start();

        try {
            // 休眠2秒，让线程t1运行一段时间
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        // 线程2中断线程t1 (main主线程中断)
        t1.interrupt();

    }
}
